`<template>
	<view class="box">
		<!-- 标签栏 -->
		<view class="tabs flex">
			<view class="tab" :class="active===index?'tabshow':''" v-for="(item,index) of list1" :key="index"
				@click="checkNav(index)">
				<view>{{item.name}}</view>
				<view class="tab-bg"></view>
			</view>
		</view>

		<!-- 空列表 -->
		<view class="none" v-if="!list.length">
			<view class="none-img f-w">
				<image src="https://jw.xzsw2021.com/static/big/icon_257@2x.png" mode="" v-if="active===0"></image>
				<image src="https://jw.xzsw2021.com/static/client/icon_66@2x.png" mode="" v-else></image>
			</view>
			<view class="none-name f30" v-if="active===0">暂时没有任何关注的店铺~</view>
			<view class="none-name f30" v-else>暂时没有任何收藏的商品~</view>
			<view class="none-btn" @click="goSpellGroup">去首页逛逛</view>
		</view>
		<!-- 订单列表 -->
		<view class="content" v-else>
			<template v-if="active===0">
				<view class="card flex" v-for="(item,index) of list" :key="index">
					<view class="img f-w">
						<image :src="item.merchant.mer_avatar" mode=""></image>
					</view>
					<view class="right">
						<view class="one flex">
							<view class="f28 bold hide-line2">{{item.merchant.mer_name + `( ${item.merchant.market} )`}}
							</view>
							<view class="f22 tag">生鲜好店</view>
						</view>
						<!-- 关注时间 -->
						<view class="two f22 c666">
							{{item.create_time ? item.create_time+'关注':'暂无关注时间'}}
						</view>
						<view class="three">
							<view @click="goShop(item.merchant.mer_id)">进店逛逛</view>
						</view>
					</view>
				</view>
			</template>
			<template v-else>
				<view class="card2 flex" v-for="(item,index) of list" :key="index">
					<view class="img2 f-w">
						<image :src="item.spu.image" mode=""></image>
					</view>
					<view class="right">
						<view class="one">
							<view class="f28 bold hide-line2">{{item.spu.store_name || '暂无商品介绍'}}</view>
						</view>
						<!-- 关注时间 -->
						<view class="two f22 c666 fw-bt">
							<view class="tag2 red">{{item.merchant || '暂无店名'}}</view>
							<view v-if="item.create_time">{{item.create_time}}关注</view>
						</view>
						<view class="three fw-bt">
							<view class="f24 c999"><text class="red">￥<text
										class="bold f28">{{item.spu.price}}</text></text>/份</view>
							<view class="btn" @click="productDetails(item)">购买</view>
						</view>
					</view>
				</view>
			</template>
		</view>
	</view>
</template>

<script>
	import {
		getUserCollectionProductApi,
		getUserCollectionMerchantApi
	} from '@/api/user'
	export default {
		data() {
			return {
				orign: '', //用于满汉全席任务	
				active: 0, //
				list1: [{
					name: '关注的店铺',
				}, {
					name: '收藏的商品',
				}], //标签
				list: [], //订单列表
				search: {
					page: 0,
					limit: 15
				}
			}
		},
		onLoad(options) {

		},
		onShow() {
			this.$countTime(this.list, 'time1', 'djs');
			this.getAj();
		},
		methods: {
			// 看看什么状态请求什么接口
			getAj() {
				if (this.active == 0) {
					//关注店铺列表
					// this.getChopping();
					getUserCollectionMerchantApi(this.search).then(res => {
						this.list = res.data.list;
					}).catch(err => {

					})
				} else {
					// this.getCommodity();
					//关注商品
					getUserCollectionProductApi(this.search).then(res => {
						this.list = res.data.list
					}).catch(err => {

					})
				}
			},
			// 切换nav
			checkNav(index) {
				this.active = index;
				this.list = []; //初始化
				this.search.page = 0
				this.getAj();
			},
			// 进店逛逛
			goShop(id) {
				uni.navigateTo({
					url: '/pages/client/shop/shop?id=' + id
				})
			},
			productDetails(product) {
				uni.navigateTo({
					url: "/pages/client/shop/shop-detail/shop-detail?id=" + product.spu.product_id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.box {
		.tabs {
			// height: 97rpx;
			padding: 24rpx 20rpx 15rpx;

			.tab {
				margin-right: 115rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				color: #999;
				font-size: 32rpx;
				text-align: center;

				.tab-bg {
					margin-top: 10rpx;
					width: 40rpx;
					height: 6rpx;
					background: #fff;
					border-radius: 3rpx;
				}
			}

			.tabshow {
				font-weight: bold;
				color: #333;

				// transition: .5s;
				.tab-bg {
					background: #109C7A;
				}
			}
		}

		.none {
			text-align: center;

			.none-img {
				margin: 95rpx auto 20rpx;
				width: 346rpx;
				height: 328rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.none-desc {
				margin-top: 20rpx;
			}

			.none-name {
				margin-top: 75rpx;
			}

			.none-btn {
				margin: 70rpx auto 0;
				width: 300rpx;
				height: 100rpx;
				line-height: 100rpx;
				text-align: center;
				font-size: 32rpx;
				color: #fff;
				background: linear-gradient(64deg, #2BCCA5, #22B591);
				box-shadow: 0rpx 4rpx 6rpx 0rpx rgba(20, 187, 146, 0.4);
				border-radius: 10rpx;
			}
		}

		.content {
			min-height: calc(100vh - 97rpx);
			padding: 0 20rpx 80rpx;
			overflow: hidden;
			box-sizing: border-box;

			.tag {
				// display: inline-block;
				flex-grow: 0;
				margin-left: 10rpx;
				max-height: 30rpx;
				padding: 2rpx 6rpx;
				background: linear-gradient(90deg, #00D058, #00C45A);
				border-radius: 4rpx;
				color: #fff;
			}

			.tag2 {
				padding: 0 4rpx;
				font-size: 20rpx;
				border: 1rpx solid #F83535;
				border-radius: 4rpx;
			}

			.card {
				padding: 27rpx 0 20rpx;
				border-bottom: 1rpx solid #eee;

				.img {
					flex-shrink: 0;
					width: 120rpx;
					height: 120rpx;

					image {
						width: 100%;
						height: 100%;
						border-radius: 12rpx;
					}
				}

				.right {
					flex: 1;
					margin-left: 15rpx;

					.one {
						.bold {
							max-width: 400rpx;
						}
					}

					.two {
						margin: 10rpx 0 10rpx;
						height: 28rpx;
					}

					.three {
						text-align: right;

						&>view {
							display: inline-block;
							width: 140rpx;
							height: 50rpx;
							line-height: 50rpx;
							text-align: center;
							font-size: 26rpx;
							background: #FFFFFF;
							border: 1rpx solid #CCCCCC;
							border-radius: 25rpx;
						}
					}
				}
			}

			.card2 {
				padding: 27rpx 0 20rpx;
				border-bottom: 1rpx solid #eee;

				.img2 {
					flex-shrink: 0;
					width: 190rpx;
					height: 190rpx;

					image {
						width: 100%;
						height: 100%;
						border-radius: 10rpx;
					}
				}

				.right {
					flex: 1;
					margin-left: 15rpx;

					.one {
						// height: 72rpx;
					}

					.two {
						margin: 10rpx 0 32rpx;
					}

					.three {
						.btn {
							width: 140rpx;
							height: 50rpx;
							line-height: 50rpx;
							text-align: center;
							color: #666;
							font-size: 26rpx;
							background: #FFFFFF;
							border: 1rpx solid #CCCCCC;
							border-radius: 25rpx;
						}
					}
				}
			}

			// .btn{
			// 	width: 160rpx;
			// 	height: 60rpx;
			// 	line-height: 60rpx;
			// 	font-size: 24rpx;
			// 	color: #fff;
			// 	text-align: center;
			// 	background: linear-gradient(64deg, #2BCCA5, #22B591);
			// 	box-shadow: 0rpx 4rpx 6rpx 0rpx rgba(20, 187, 146, 0.4);
			// 	border-radius: 10rpx;
			// }
		}
	}
</style>
